package com.hjli.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hjli.tool.PropertiesTool;

@Controller
@RequestMapping("sys/themes")
public class ThemeController {

	@RequestMapping("change")
	public @ResponseBody Map<String,Object> change(HttpServletRequest request,HttpServletResponse response) throws Exception{
		Map<String,Object> resultMap = new HashMap<String,Object>();
		if(request.getParameter("themeName")==null&&request.getParameter("themeName").toString()==""){
			resultMap.put("result", "参数错误");
			return resultMap;
		}
		String themeName = request.getParameter("themeName").toString();
		//修改主题配置
		PropertiesTool propTool = new PropertiesTool();
		String propPath = request.getSession().getServletContext().getRealPath("WEB-INF/classes/theme.properties");
		
		propTool.updatePro(propPath, "themeName", themeName);
		
		HttpSession session = request.getSession();
		session.setAttribute("themeName", themeName);
		resultMap.put("result", "success");

		return resultMap;
	}
}
